package com.yxq.mdt.app.modules.personal.presenter;

import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.personal.bean.AddressBean;
import com.yxq.mdt.app.modules.personal.bean.AddressListBean;
import com.yxq.mdt.app.modules.personal.model.AddressModel;
import com.yxq.mdt.app.net.ApiModel;

import java.util.List;

public class AddressPresenter extends BasePresenter<IAddressContract.View, AddressModel> implements IAddressContract.Presenter {


    public AddressPresenter(IAddressContract.View rootView, AddressModel model) {
        super(rootView, model);
    }

    @Override
    public void district() {
        mBaseModel.district(new ApiModel.CommonCallback<List<AddressBean>>() {
            @Override
            public void onSuccess(List<AddressBean> addressBeanList) {
                mRootView.onLoadSuccess(addressBeanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void list() {
        mBaseModel.addressList(new ApiModel.CommonCallback<AddressListBean>() {
            @Override
            public void onSuccess(AddressListBean addressBeanList) {
                mRootView.onLoadListSuccess(addressBeanList);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadListFailed(errMsg);
            }
        });
    }

    public void save(String address_id, String name, String mobile, String province_id, String city_id, String district_id, String detail) {
        mBaseModel.addressSave(address_id, name, mobile, province_id, city_id, district_id, detail, new ApiModel.CommonCallback<AddressListBean.ListBean>() {
            @Override
            public void onSuccess(AddressListBean.ListBean result) {
                mRootView.onSaveSuccess(result);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onSaveFailed(errMsg);
            }
        });
    }

    public void delete(int position, String address_id) {
        mBaseModel.addressDelete(address_id, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                mRootView.onDeleteSuccess(position, result);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onDeleteFailed(errMsg);
            }
        });
    }

    public void setDefault(String address_id) {
        mBaseModel.setDefault(address_id, new ApiModel.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                mRootView.onSetDefaultSuccess(result);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onSetDefaultFailed(errMsg);
            }
        });
    }
}
